package com.cx.interact.server.rule.service;

import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Service;
import com.cx.base.apiModel.ApiModel;
import com.cx.base.autoDoc.annotations.AutoDocField;
import com.cx.base.autoDoc.annotations.AutoDocMethod;
import com.cx.base.autoDoc.annotations.AutoDocType;
import com.cx.base.exception.SoaException;
import com.cx.base.server.BaseServer;
import com.cx.base.utils.LogInfoUtil;
import com.cx.base.utils.StringUtil;
import com.cx.interact.interfaces.rule.dto.UserMsgDTO;
import com.cx.interact.interfaces.rule.service.RuleService;
import com.cx.interact.server.rule.dao.GeneralSqlDAO;

@Service
@Component
@AutoDocType("规则查询")
public class RuleServiceImpl extends BaseServer implements RuleService{

	@Resource
	private GeneralSqlDAO generalSqlDAO;
	
	@Override
	@AutoDocMethod(name = "查询用户在活动中参与次数",  desc="全为必传参数",resClazz = Integer.class)
	public ApiModel queryUserTime(@AutoDocField("活动模板ID") String templateId,@AutoDocField("活动ID") String actId,@AutoDocField("用户唯一码") String uniqueCode) throws SoaException {
		System.out.println("进入了。。。。");
		UserMsgDTO dto = new UserMsgDTO();
		if(StringUtil.isNotNull(templateId) && StringUtil.isNotNull(actId) && StringUtil.isNotNull(uniqueCode)){
			try {
				HashMap<String, Object> paraMap = new HashMap<String, Object>();
				paraMap.put("templateId", templateId);
				paraMap.put("actId", actId);
				paraMap.put("uniqueCode", uniqueCode);
				
				dto.setTime(generalSqlDAO.dsQueryInt(paraMap, "DS_USER_TIME_BY_UNIQUE_CODE"));
				
				return buildSuccMsg(dto);
			} catch (Exception e) {
				LogInfoUtil.error(this.getClass(), "查询用户在活动中参与次数", "出错", e);
			}
			
		}
		
		return buildErrorMsg(null, DATA_ERROR, FAIL);
	}

}
